package net.edu_soft.ec.asset.controller;

import net.edu_soft.ec.asset.pojo.SysLog;
import net.edu_soft.ec.asset.service.SysLogService;
import net.edu_soft.ec.common.util.ResultVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RequestMapping(value = "/log")
@RestController
public class SysLogController {

    @Autowired
    private SysLogService sysLogService;

    /***
     *
     * @param userName 操作用户
     * @param operation 操作
     * @param createDate 日期
     * @param sort 排序 1降序排序 2升序
     * @param upOrDown 升降 1之后 2之前
     * @param pageNum 当前页
     * @param pageSize 每页数
     * @return
     */
    @RequestMapping(value = "/find")
    @RequiresPermissions("log:find")
    public ResultVo find(String userName, String operation, Date createDate,Integer sort,Integer upOrDown, Integer pageNum, Integer pageSize){
        SysLog sysLog = new SysLog();
        sysLog.setUserName(userName);
        sysLog.setOperation(operation);
        sysLog.setCreateDate(createDate);
        return ResultVo.succeed("",sysLogService.find(sysLog,sort,upOrDown,pageNum,pageSize));
    }

    @RequestMapping(value = "/del")
    @RequiresPermissions("log:del")
    public ResultVo del(String ids,Integer isDel){
        int i = sysLogService.del(ids,isDel);
        if(i==1){
            return ResultVo.succeed("删除成功",i);
        }
        return ResultVo.failed(210,"删除失败",null);
    }

}
